package com.springboot.mybatis.mapper;

import com.springboot.mybatis.entity.Film;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FilmMapper {
    String selectAllStr = "select * from film";
    String selectByIdStr = "select * from film where film_id = #{filmId}";
    String selectByTitle = "select * from film where title like concat('%',#{title},'%')";

    @Select(selectAllStr)
    List<Film> selectAll ();

    @Select(selectByIdStr)
    Film selectById (Integer id);

    @Select(selectByTitle)
    List<Film> selectByTitle (String title) ;

    String insertStr = "insert into film values(null,#{title},#{description},#{releaseYear}," +
            "#{languageId},#{originalLanguageId},#{rentalDuration},#{rentalRate}," +
            "#{length},#{replacementCost},#{rating},#{specialFeatures},now())";

    @Insert(insertStr)
    void insertOne (Film film);

    String updateStr = "update film set title=#{title},description=#{description}," +
            "release_year=#{releaseYear},language_id=#{languageId}," +
            "original_language_id=#{originalLanguageId},rental_duration=#{rentalDuration}," +
            "rental_rate=#{rentalRate},length=#{length},replacement_cost=#{replacementCost}," +
            "rating=#{rating},special_features=#{specialFeatures},last_update=now()" +
            "where film_id = #{filmId}";

    @Update(updateStr)
    void updateOne (Film film);

    String deleteStr = "delete from film where film_id = #{filmId}";

    @Delete(deleteStr)
    void deleteOne (Integer id);
}
